package com.dark;

import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;

import java.util.Collection;

/**
 * Created by tengxue on 16-6-14.
 * map键值结构的扩展.把相同key的值存放到了一个集合当中.
 */
public class MultimapDemo {
    public static void main(String[] args){
        Multimap<String,String> multimap= ArrayListMultimap.create();
        multimap.put("a","a");
        multimap.put("a","b");
        multimap.put("a","c");
        //遍历key是a的元素
        Collection<String> collection= multimap.get("a");
        for (String entity:collection){

            System.out.println("the element is :"+entity);
        }

        System.out.println("-----------------------------------------------------------");
        multimap.put("b","d");
        multimap.put("b","e");
        multimap.put("b","f");


        System.out.println("the multimap size is:" + multimap.size());
        System.out.println("-----------------------------------------------------------");

        for (String key:multimap.keySet()){
            System.out.println("the multimap key is:----------->" +key);
            for (String value:multimap.get(key)){
                System.out.println("the multimap value is:---------->" +value);
            }

            System.out.println("-----------------------------------------------------------");
        }
    }
}
